package com.code.leetcode.center50;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/7/27 13:37
 */
public class The125_T {

    public boolean isPalindrome(String s) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (Character.isLetterOrDigit(c)) {
                builder.append(Character.toLowerCase(c));
            }
        }
        StringBuilder reverse = new StringBuilder(builder).reverse();
        return reverse.toString().equals(builder.toString());
    }


    public boolean isPalindromeT(String s) {
        int len = s.length();
        int left = 0, right = len - 1;
        while (left < right) {
            if (left < right && !Character.isLetterOrDigit(s.charAt(left))) {
                left++;
            }
            if (left < right && !Character.isLetterOrDigit(s.charAt(right))) {
                right--;
            }
            if (left < right) {
                if (Character.toLowerCase(s.charAt(left)) != Character.toLowerCase(s.charAt(right))) {
                    return false;
                }
            }
            left++;
            right--;
        }
        return true;
    }



}
